<template>
	<view class="content">
		<u-sticky>
			<view class="u-padding-20 u-flex u-row-between" style="background: #FFFFFF;">
				<view class="u-flex" v-if="show">
					<image src="/static/check2.png" style="width: 40rpx;height: 40rpx;"></image>
					<view @click="ClassifyChange(index,item)" v-for="(item,index) in Classify" :key="index"
						class="u-margin-left-20 $u-type-info" :class="current==index?'Change':''">
						{{item.classifyName}}
					</view>
				</view>


				<view :style="{'width':show?'300rpx':'700rpx'}">
					<u-search placeholder="查找自学装修" :animation="false" :show-action="false"
						:v-model="initial.parm.keyword" bg-color="#fff" border-color="#333" @change="Skeyword"
						@focus="focus" @blur="blur">
					</u-search>
				</view>

			</view>
		</u-sticky>


		<u-tabs :isImg="true" :list="nav" name="classifyName" @change="change" :current="current1" height="110">
		</u-tabs>

		<u-gap bg-color="#f1f1f1" height="10"></u-gap>

		<view v-for="(item,index) in list" :key="index" class="list" @click="go_detail(item)">
			<view class="u-padding-20">

				<view class="u-line-2 " style="font-size: 32rpx;text-align: left;">
					<u-tag text="置顶" size="mini" mode="dark" v-if="item.top"></u-tag>
					<text class="u-margin-left-10">{{item.title}}</text>
				</view>
				<view style="color: #999;margin-top: 20rpx;">作者:{{item.writer}}</view>
			</view>
			<view style="">
				<u-image :src="item.cover" width="280" height="180" border-radius="20"></u-image>
			</view>
		</view>

<backTop></backTop>



		<u-loadmore :status="initial.status" />



	</view>
</template>

<script>
	import loader from '@/common/loadPage.js';

	import search from "../../components/search";
	import check from "../../components/check";

import backTop from '../../components/backTop';
	export default {
		components: {
			search,
			check,
			backTop,
		},
		mixins: [loader],
		computed: {
			watchCurrent() {
				var current = this.current;
				var Classify = this.Classify;
				var nav = this.nav;
				var current1 = this.current1;
				return {
					current,
					Classify,
					nav,
					current1
				}
			}
		},
		watch: {
			watchCurrent: {
				immediate: true,
				handler(v) {
					if (v.Classify.length) {
						this.nav = v.Classify[v.current].child;
					}
					if (v.nav.length) {
						this.initial.parm.article_classify_id = v.nav[v.current1].id;
						this.initial.page = 1;
						this.getGoods()
					}
				}
			},

		},
		data() {
			return {
				list: [],
				initial: {
					geturl: "/index/article",
					parm: {
						article_classify_id: '',
						keyword: ""
					},
				},
				Classify: [],
				nav: [],
				current: 0,
				current1: 0,
				show: true
			}
		},
		async onLoad() {
			this.getclass()
			this.getGoods()
		},
		methods: {
			focus(e) {
				this.show = false
			},
			blur(e) {
				this.show = true
			},
			ClassifyChange(e) {
				this.current1 = 0;
				this.current = e;
			},
			// 搜索
			Skeyword(e) {
				this.initial.parm.keyword = e;
				this.getGoods()
			},
			go_detail(item) {
				uni.navigateTo({
					url: "./article?id=" + item.id
				})
			},
			// 获得分类
			getclass() {
				this.$u.post('/index/articleClassify', {}).then(res => {
					this.Classify = res;
				}).catch(err => {})
			},
			// 帅选
			select(e) {
				this.nav = e.child;
			},
			// current切换
			change(index) {

				this.current1 = index;
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #F8F8F8;
	}

	.list {
		background: #FFFFFF;
		width: 750rpx;
		margin-bottom: 20rpx;
		padding: 20rpx;
		display: flex;
		justify-content: space-between;

	}

	.mask {
		position: absolute;
		background-color: rgba(0, 0, 0, 0.3);
		width: 100%;
		height: 100%;
		left: 0;
		top: 0;
		z-index: 99;
		border-radius: 20rpx;

		.icon {
			position: absolute;
			top: 50%;
			left: 50%;
			transform: translate(-50%, -50%);
		}
	}

	.Change {
		color: #333;
		font-weight: bold;
	}
</style>
